import { Controller } from "../../mvc/core/Controller";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { FGIconView } from "../view/footballGuess/FGIconView";
import { IView } from "../../mvc/interfaces/IView";
import { FootballGuessModule } from "../../../modules/FootballGuessModule";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { FGTeamInfo } from "../view/footballGuess/FGTeamInfo";
import { EActiveType } from "../../../Message/Public/EActiveType";
import { IFootballGuessModule } from "../../../modules/interfaces/IFootballGuessModule";
type int = number;
//class FootballGuessController
    
    export  class FootballGuessController extends Controller
    {
        constructor()
        {
            
            super();Dispatcher.addEventListener(EventName.FootballGuessGetInfos, this.onFootballGuessGetInfosHandler);
            Dispatcher.addEventListener(EventName.FootballGuessGetInfosSuccess, this.onFootballGuessGetInfosSuccessHandler);
            Dispatcher.addEventListener(EventName.FootballGuessTeam, this.onFootballGuessTeamHandler);
            Dispatcher.addEventListener(EventName.FootballGuessGetReward, this.onFootballGuessGetRewardHandler);
            Dispatcher.addEventListener(EventName.FootballGuessAlertWindowOpen, this.onFootballGuessAlertWindowOpenHandler);
            Dispatcher.addEventListener(EventName.AcitveTimeUpdate, this.onAcitveTimeUpdateHandler);
            return;
        }

        public get iconView(): FGIconView
        {
            if (!this._iconView) 
            {
                this._iconView = new FGIconView();
            }
            return this._iconView;
        }

        public /* override */ get view(): IView
        {
            return this.initView();
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            return;
        }

        protected /* override */ initView(): IView
        {
            if (this._fgModule == null) 
            {
                this._fgModule = new FootballGuessModule();
            }
            return this._fgModule;
        }

        /* internal  */onFootballGuessGetInfosHandler(arg1: DataEvent): void
        {
            GameProxy.daily.footballGameInfo();
            return;
        }

        /* internal  */onFootballGuessGetInfosSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["gamesInfo"] as Array<any>;
            var loc2=arg1.data["hadGetRewards"] as Map<any, any> /* flash.utils.Dictionary */;
            var loc3=arg1.data["rewards"] as Map<any, any> /* flash.utils.Dictionary */;
            cache.footballGuess.gameInfos = loc1;
            cache.footballGuess.hadGetRewards = loc2;
            cache.footballGuess.rewards = loc3;
            if (this._fgModule) 
            {
                this._fgModule.updateGameInfos(loc1);
            }
            return;
        }

        /* internal  */onFootballGuessTeamHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["type"] as int;
            var loc2=arg1.data["group"] as int;
            var loc3=arg1.data["team"] as int;
            var loc4=arg1.data["callBack"] as Function;
            GameProxy.daily.footballGameGuess(loc1, loc2, loc3, loc4);
            return;
        }

        /* internal  */onFootballGuessGetRewardHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["itemCode"] as int;
            var loc2=arg1.data["callBackFun"] as Function;
            GameProxy.daily.footballReward(loc1, loc2);
            return;
        }

        /* internal  */onFootballGuessAlertWindowOpenHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["teamInfo"] as FGTeamInfo;
            var loc2=arg1.data["isA"] as Boolean;
            var loc3=arg1.data["clickFun"] as Function;
            if (this._fgModule) 
            {
                this._fgModule.showAlertWindow(loc1, loc2, loc3);
            }
            return;
        }

        /* internal  */onAcitveTimeUpdateHandler(arg1: DataEvent): void
        {
            var loc1=cache.active.isActiveInEffect(EActiveType._EActiveTypeFootballGameGuess);
            if (loc1) 
            {
                this.iconView.show();
            }
            else if (this._iconView) 
            {
                this._iconView.hide();
            }
            return;
        }

        private /* var */_fgModule: IFootballGuessModule;

        private /* var */_iconView: FGIconView;
    }
